package com.yidu.best.basicSetup.custodian.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.best.basicSetup.custodian.domain.Custodian;
import com.yidu.best.basicSetup.custodian.domain.CustodianVo;
import com.yidu.best.basicSetup.custodian.service.CustodianService;
import com.yidu.best.systemManagement.userControl.util.IDGenerator;

@Controller
@RequestMapping("/custodian/")
public class CustodianController {
	@Autowired
	private CustodianService custodianService;

	public CustodianController() {
		super();
	}

	public CustodianController(CustodianService custodianService) {
		super();
		this.custodianService = custodianService;
	}

	public CustodianService getCustodianService() {
		return custodianService;
	}

	public void setCustodianService(CustodianService custodianService) {
		this.custodianService = custodianService;
	}
	@RequestMapping("custodianList")
	public String skipRoleList() {
		return "sys/custodian/custodianList";	
	}
	/**
	 * 查找所有管理人信息
	 * @param custodianVo 管理人对象
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="custodians",method=RequestMethod.GET)
	public Map<String, Object> queryCustodianDate(CustodianVo custodianVo){
		
		Map<String, Object> custodianMap = custodianService.queryCustodianMapByCriteriaWithPage(custodianVo);
		return custodianMap;
	}
	@RequestMapping(value="save",method=RequestMethod.POST)
	@ResponseBody
	public int saveCustodian(Custodian custodian) {
		int row = 0;
		if(custodian.getCustodianId()==null || "".equals(custodian.getCustodianId())) {
			custodian.setCustodianId(IDGenerator.getId());
			
			row =custodianService.addCustodian(custodian);
		}else {
			row = custodianService.updateCustodian(custodian);
		}
		return row;
	}
	@ResponseBody
	@RequestMapping(value="deleteCustodian",method=RequestMethod.DELETE)
	public int deleteUser(String custodianIdStr) {
		System.out.println("进入222222"+custodianIdStr);
		int deleteById = custodianService.deleteCustodian(custodianIdStr);
		return deleteById;
	}
	@RequestMapping(value="logicdelete",method=RequestMethod.POST)
	@ResponseBody
	public int logicdelete(Custodian custodian) {
		int logicDelete = custodianService.logicDelete(custodian);
		return logicDelete;
		
	}
}
